﻿using RabbitMQ.Client;
using System.Text;

namespace PoemGame.MessageSender.MQ
{
    public class MessageSenderMQ:IMessageSender
    {
        public Task SendMessage(string messageType, string messageBody)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "127.0.0.1",
                UserName = "admin",
                Password = "admin",
                VirtualHost = "my_vhost"
            };
            using (var connection = factory.CreateConnection())
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: messageType,
                    durable: false,
                    exclusive: false,
                    autoDelete: false,
                    arguments: null);


                var body = Encoding.UTF8.GetBytes(messageBody);

                channel.BasicPublish(exchange: "",
                    routingKey: messageType,
                    basicProperties: null,
                    body: body);

            }
            return Task.CompletedTask;
        }
    }
}